package com.wenyu.wenyuyuedu.adapter.homepagefragment;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.Html;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.activity.LoginActivity;
import com.wenyu.wenyuyuedu.activity.homepage.MyAttentionActivity;
import com.wenyu.wenyuyuedu.activity.personage.OtherPublishActivity;
import com.wenyu.wenyuyuedu.bean.JudgeWhetherJoinBean;
import com.wenyu.wenyuyuedu.bean.circle.JoinCircleBean;
import com.wenyu.wenyuyuedu.bean.homepager.DeleteCommentBean;
import com.wenyu.wenyuyuedu.bean.homepager.MyAttentionInformBean;
import com.wenyu.wenyuyuedu.bean.homepager.NewAllAttentionBean;
import com.wenyu.wenyuyuedu.bean.homepager.PostCommentBean;
import com.wenyu.wenyuyuedu.global.ApiWrapper;
import com.wenyu.wenyuyuedu.server.circle.JoinCircleServer;
import com.wenyu.wenyuyuedu.server.homepager.DeleteCommentServer;
import com.wenyu.wenyuyuedu.server.homepager.Home_AllAtten_Server;
import com.wenyu.wenyuyuedu.server.homepager.JudgeWhetherJoin;
import com.wenyu.wenyuyuedu.server.homepager.PostCommentServer;
import com.wenyu.wenyuyuedu.utils.AbSharedUtil;
import com.wenyu.wenyuyuedu.utils.DeleteHtml;
import com.wenyu.wenyuyuedu.utils.DensityUtil;
import com.wenyu.wenyuyuedu.utils.ListViewAndListView;
import com.wenyu.wenyuyuedu.utils.MyToast;
import com.wenyu.wenyuyuedu.utils.SharedConstants;
import com.wenyu.wenyuyuedu.utils.ShowHideJianPan;
import com.wenyu.wenyuyuedu.utils.TimeStyle;
import com.wenyu.wenyuyuedu.view.CircleImageView;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/2/23.
 * 首页--我的关注--帖子详情的adapter
 */

public class AttenttionDetailAdapter extends BaseAdapter {
    private List<NewAllAttentionBean.InfoBean.AllCommentBean> forumLzlReply = new ArrayList<>();
    private MyAttentionActivity context;
    private View view;
    private String mName;
    private String token;

    private String object_id;
    private List<NewAllAttentionBean.InfoBean.AllCommentBean.SonCommentBean> son_comment;
    private SecondCommentAdapter commentAdapter;
    private String secondId;
    private String secondToUid;
    private String secondPid;
    private String secondObjectId;
    private String uid;
    private String pid;
    private String id;
    private String user_uid;

    public AttenttionDetailAdapter(MyAttentionActivity invitationDetailActivity, String name) {
        this.mName = name;
        this.context = invitationDetailActivity;
    }


    @Override
    public int getCount() {
        return forumLzlReply.size();
    }

    @Override
    public Object getItem(int i) {
        return forumLzlReply.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        InvitationDetailHolder holder = null;
        if (view == null) {
            holder = new InvitationDetailHolder();
            view = View.inflate(context, R.layout.attention_detail_item, null);
            holder.invitation_nickname = (TextView) view.findViewById(R.id.invitation_nickname);
            holder.invitation_releasetime = (TextView) view.findViewById(R.id.invitation_releasetime);
            //holder.item_zan_count = (TextView) view.findViewById(R.id.item_zan_count);
            //  holder.invitation_content = (TextView) view.findViewById(invitation_content);
            holder.invitation_head = (CircleImageView) view.findViewById(R.id.invitation_head);
            holder.invitation_down = (ImageView) view.findViewById(R.id.invitation_down);
            holder.tv_huifu_name = (TextView) view.findViewById(R.id.tv_huifu_name);
            holder.lv_huifu = (ListViewAndListView) view.findViewById(R.id.lv_huifu);
            view.setTag(holder);
        } else {
            holder = (InvitationDetailHolder) view.getTag();
        }
        /*被回复人的昵称*/
        String to_comment_name = forumLzlReply.get(i).getTo_comment_name();
        boolean equals = mName.equals(to_comment_name);
        if (mName.equals(to_comment_name)) {
            //   etInvitation.setHint(Html.fromHtml("<font color= '#576b95'> 评论@</font>" + nickname1 + ":"));
            String content = forumLzlReply.get(i).getContent();
            holder.tv_huifu_name.setText(Html.fromHtml("" + content));
        } else {
            String content = forumLzlReply.get(i).getContent();
            holder.tv_huifu_name.setText(Html.fromHtml("回复" + "<font color= '#576b95'>" + to_comment_name + "</font>" + ":" + content));

        }
        /*评论内容的点击事件*/
       /* holder.tv_huifu_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.JudeWheTherItemMessage(i);
            }
        });*/
        /*点击头像进入个人主页*/
        holder.invitation_head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String uid = forumLzlReply.get(i).getUid();
                Intent intents = new Intent();
                intents.setClass(context, OtherPublishActivity.class);
                intents.putExtra("userid", uid);
                context.startActivity(intents);
            }
        });
        Glide.with(context)
                .load(forumLzlReply.get(i).getComment_icon())
                .into(holder.invitation_head);
        String ctime = forumLzlReply.get(i).getCtime();
        String s = TimeStyle.publishTime(ctime);
        holder.invitation_releasetime.setText(s);
        holder.invitation_nickname.setText(forumLzlReply.get(i).getComment_name());
        /*子评论中的内容*/
        son_comment = forumLzlReply.get(i).getSon_comment();
        int size = son_comment.size();
        commentAdapter = new SecondCommentAdapter(context, i);
        holder.lv_huifu.setAdapter(commentAdapter);
        if (son_comment != null) {
            commentAdapter.addAll(son_comment);
        }
        /*一级回复下的二级评论的条目点击事件*/
        holder.lv_huifu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                SecondCommentAdapter adapter = (SecondCommentAdapter) adapterView.getAdapter();
                int position = adapter.position;
                JudeWheTherMessage(position, i);
            }
        });
        /*二级评论的长按事件---可以长按举报和删除*/
        holder.lv_huifu.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                SecondCommentAdapter adapter = (SecondCommentAdapter) adapterView.getAdapter();
                int position = adapter.position;
                List<NewAllAttentionBean.InfoBean.AllCommentBean.SonCommentBean> son_comment = forumLzlReply.get(position).getSon_comment();
                String uid = son_comment.get(i).getUid();
                String id = son_comment.get(i).getId();
                if (user_uid.equals(uid)) {
                    showPopUpWindow(view, i, id, son_comment);
                } else {
                    showPopUpWindowJuBao(view,i,uid,id);
                }
                return true;
            }
        });
        return view;
    }
    /**
     * 显示举报的弹框
     */
    private PopupWindow popWindowJuBao;

    private void showPopUpWindowJuBao(final View view, final int i,final String uid,final String id) {
        TextView window = new TextView(context);
        window.setText("举报");
        window.setTextColor(context.getResources().getColor(R.color.white));
        int padding = DensityUtil.dip2px(context, 10);
        int bottom = DensityUtil.dip2px(context, 15);
        window.setPadding(padding, padding, padding, bottom);
        window.measure(0, 0);
        popWindowJuBao = new PopupWindow(window, window.getMeasuredWidth(), window.getMeasuredHeight(), true);
        popWindowJuBao.setBackgroundDrawable(context.getApplicationContext().getResources().getDrawable(R.drawable.pop_top));
        popWindowJuBao.setOutsideTouchable(true);

        Log.i("TAG", "showPopUpWindow: " + padding);
        //第一次显示控件的时候宽高会为0
        int deleteHeight = window.getHeight() == 0 ? 100 : window.getHeight();
        int deleteWidth = window.getWidth() == 0 ? 212 : window.getWidth();
        popWindowJuBao.showAsDropDown(view, (view.getWidth() - deleteWidth) / 2, -view.getHeight() - deleteHeight);
        window.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popWindowJuBao.dismiss();
                reportCommentDialog(uid,id);
            }
        });
        popWindowJuBao.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                view.setBackgroundColor(context.getResources().getColor(R.color.white));
            }
        });
    }
    /*举报的列表---帖子的*/
    private Dialog respotCommentDialog;

    private void reportCommentDialog(final String uid,final String id) {
        View view = context.getLayoutInflater().inflate(R.layout.comment_report_dialog,
                null);
        respotCommentDialog = new Dialog(context, R.style.transparentFrameWindowStyle);
        respotCommentDialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        Button cancle = (Button) view.findViewById(R.id.report_cancel);
        Button advertising_grabage = (Button) view.findViewById(R.id.advertising_grabage);
        Button plagiarize = (Button) view.findViewById(R.id.plagiarize);
        Button hostility = (Button) view.findViewById(R.id.hostility);
        Button other = (Button) view.findViewById(R.id.other);
        advertising_grabage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InInvitationform(uid, id, 3 + "", 1 + "");
            }
        });
        plagiarize.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InInvitationform(uid, id, 3 + "", 2 + "");
            }
        });
        hostility.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InInvitationform(uid, id, 3 + "", 3 + "");
            }
        });
        other.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InInvitationform(uid, id, 3 + "", 4 + "");
            }
        });
        /*关闭dialog*/
        cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                respotCommentDialog.cancel();
            }
        });
        Window window = respotCommentDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = context.getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        respotCommentDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        respotCommentDialog.setCanceledOnTouchOutside(true);
        respotCommentDialog.show();
    }
    /*举报的接口-----可以举报帖子--可以举报圈子-=------inform(是圈子还是帖子)--- type(是举报的类型)*/
    private void InInvitationform(String toUid, String ObjectId, String inFormTyoe, String type) {
        Home_AllAtten_Server home_allAtten_server = ApiWrapper.getInstance().create(Home_AllAtten_Server.class);
        Call<MyAttentionInformBean> myAttentionInformBeanCall = home_allAtten_server.postInform(token, toUid, ObjectId, inFormTyoe, type);
        myAttentionInformBeanCall.enqueue(new Callback<MyAttentionInformBean>() {
            @Override
            public void onResponse(Call<MyAttentionInformBean> call, Response<MyAttentionInformBean> response) {
                MyAttentionInformBean body = response.body();
                if (body != null) {
                    int code = body.getCode();
                    if (code == 1) {
                        if (respotCommentDialog != null) {
                            respotCommentDialog.cancel();
                        }
                        MyToast.showToast(context, "举报成功，等待审核", Toast.LENGTH_SHORT);
                    } else if (code == 0) {
                        showLoginDoalog();
                    } else if (code == 2900) {
                        MyToast.showToast(context, "需要登陆后才可以操作", Toast.LENGTH_SHORT);
                    } else if (code == 2901) {
                        MyToast.showToast(context, "抱歉您的账户被暂时限制了，无法进行此操作", Toast.LENGTH_SHORT);
                    } else if (code == 2902) {

                    } else if (code == 2904) {
                        MyToast.showToast(context, "系统繁忙请稍后再试！", Toast.LENGTH_SHORT);
                    }
                }
            }

            @Override
            public void onFailure(Call<MyAttentionInformBean> call, Throwable t) {
                MyToast.showToast(context, "系统繁忙请稍后再试！", Toast.LENGTH_SHORT);
            }
        });
    }
    /**
     * 显示删除的弹框
     */
    private PopupWindow popWindow;

    private void showPopUpWindow(final View view, final int i, final String id, final List<NewAllAttentionBean.InfoBean.AllCommentBean.SonCommentBean> son_comment) {
        TextView window = new TextView(context);
        window.setText("删除");
        window.setTextColor(context.getResources().getColor(R.color.white));
        int padding = DensityUtil.dip2px(context, 10);
        int bottom = DensityUtil.dip2px(context, 15);
        window.setPadding(padding, padding, padding, bottom);
        window.measure(0, 0);
        popWindow = new PopupWindow(window, window.getMeasuredWidth(), window.getMeasuredHeight(), true);
        popWindow.setBackgroundDrawable(context.getApplicationContext().getResources().getDrawable(R.drawable.pop_top));
        popWindow.setOutsideTouchable(true);

        Log.i("TAG", "showPopUpWindow: " + padding);
        //第一次显示控件的时候宽高会为0
        int deleteHeight = window.getHeight() == 0 ? 100 : window.getHeight();
        int deleteWidth = window.getWidth() == 0 ? 212 : window.getWidth();
        popWindow.showAsDropDown(view, (view.getWidth() - deleteWidth) / 2, -view.getHeight() - deleteHeight);
        window.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popWindow.dismiss();
                /*帖子的id*/
                deleteComment(id, i, son_comment);
            }
        });
        popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                view.setBackgroundColor(context.getResources().getColor(R.color.white));
            }
        });
    }

    /*删除评价*/
    private void deleteComment(final String id, final int i, final List<NewAllAttentionBean.InfoBean.AllCommentBean.SonCommentBean> son_comment) {
        DeleteCommentServer deleteCommentServer = ApiWrapper.getInstance().create(DeleteCommentServer.class);
        Call<DeleteCommentBean> deleteComment = deleteCommentServer.getDeleteComment(token, id);
        deleteComment.enqueue(new Callback<DeleteCommentBean>() {
            @Override
            public void onResponse(Call<DeleteCommentBean> call, Response<DeleteCommentBean> response) {
                DeleteCommentBean body = response.body();
                if (body != null) {
                    int code = body.getCode();
                    if (code == 1) {
                        MyToast.showToast(context, "删除成功", Toast.LENGTH_SHORT);
                        son_comment.remove(i);
                        notifyDataSetChanged();
                    } else if (code == 7200) {
                        MyToast.showToast(context, "登陆后才可以删除", Toast.LENGTH_SHORT);
                    } else if (code == 7201) {
                        MyToast.showToast(context, "该评价不存在", Toast.LENGTH_SHORT);
                    } else if (code == 7202) {
                        MyToast.showToast(context, "已经删除过了", Toast.LENGTH_SHORT);
                    } else if (code == 7203) {
                        MyToast.showToast(context, "您无权删除别人的评价", Toast.LENGTH_SHORT);
                    }
                } else {
                    MyToast.showToast(context, "删除失败", Toast.LENGTH_SHORT);
                }
            }

            @Override
            public void onFailure(Call<DeleteCommentBean> call, Throwable t) {
                MyToast.showToast(context, "网络异常，请稍后重试", Toast.LENGTH_SHORT);
            }
        });
    }

    class InvitationDetailHolder {
        TextView invitation_item_comment_count, invitation_nickname,
                invitation_releasetime, item_zan_count;
        CircleImageView invitation_head;
        ImageView invitation_down;
        TextView tv_huifu_name;
        ListViewAndListView lv_huifu;

    }

    /*填充数据*/
    public void updateRes(List<NewAllAttentionBean.InfoBean.AllCommentBean> forumLzlReply, String token, String object_id, String uid, String id, String user_uid) {
        if (forumLzlReply != null) {
            this.forumLzlReply.clear();
            this.forumLzlReply.addAll(forumLzlReply);
            this.token = token;
            this.id = id;
            this.object_id = object_id;
            this.uid = uid;
            this.user_uid = user_uid;
            notifyDataSetChanged();
        }
    }

    public void clear() {
        this.forumLzlReply.clear();
        notifyDataSetChanged();
    }

    /*发消息前判断用户是否登录---是否加入书圈------这里指的是一级回复下的条目*/
    private void JudeWheTherMessage(final int parentPosition, final int position) {
        JudgeWhetherJoin judgeWhetherJoin = ApiWrapper.getInstance().create(JudgeWhetherJoin.class);
        Call<JudgeWhetherJoinBean> join = judgeWhetherJoin.getJoin(token, object_id);
        join.enqueue(new Callback<JudgeWhetherJoinBean>() {
            @Override
            public void onResponse(Call<JudgeWhetherJoinBean> call, Response<JudgeWhetherJoinBean> response) {
                JudgeWhetherJoinBean body = response.body();
                if (body != null) {
                    int code = body.getCode();
                    if (code == 1) {
                        showEditTextDialog();
                        pingLunHuifu(parentPosition, position);
                        ShowHideJianPan.showSoftKeyBorad(etInvitation, 80);
                    } else if (code == 0) {
                        //token 錯誤或則失效
                        showLoginDoalog();
                    } else if (code == 1600) {
                        //需要用户登陆后才可以操作
                        showLoginDoalog();
                    } else if (code == 1601) {
                        /*用户并没有加入该圈子*/
                        shoWhetherJoin();
                    } else if (code == 1602) {
                        //用户自己的帖子
                        MyToast.showToast(context, "不能给自己评论", Toast.LENGTH_SHORT);
                    }
                }
            }

            @Override
            public void onFailure(Call<JudgeWhetherJoinBean> call, Throwable t) {
                MyToast.showToast(context, "网络异常，请稍后重试", Toast.LENGTH_SHORT);
            }
        });
    }

    /*token错误或失效*/
    AlertDialog ad;
    private TextView quxiao;
    private TextView queding;

    private void showLoginDoalog() {

        ad = new AlertDialog.Builder(context).create();
        ad.show();
        Window window = ad.getWindow();
        window.setContentView(R.layout.dailog_login);
        quxiao = (TextView) window.findViewById(R.id.dialog_login_quxiao);
        queding = (TextView) window.findViewById(R.id.dialog_login_queding);
        quxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ad.dismiss();
            }
        });
        queding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AbSharedUtil.putString(context, SharedConstants.USER_TOKEN, "");
                Intent intent = new Intent();
                intent.setClass(context, LoginActivity.class);
                context.startActivity(intent);
                ad.dismiss();
            }
        });
    }

    /*顯示是否加入该圈子*/
    AlertDialog adJoin;
    private TextView quxiaoJoin;
    private TextView quedingJoin;

    private void shoWhetherJoin() {
        adJoin = new AlertDialog.Builder(context).create();
        adJoin.show();
        Window window = adJoin.getWindow();
        window.setContentView(R.layout.join_circle_dailog_login);
        quxiaoJoin = (TextView) window.findViewById(R.id.dialog_login_quxiao);
        quedingJoin = (TextView) window.findViewById(R.id.dialog_login_queding);
        quxiaoJoin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                adJoin.dismiss();
            }
        });
        quedingJoin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JiaRuCircle();
            }
        });
    }

    /*加入圈子的钮*/
    private void JiaRuCircle() {
        String token = AbSharedUtil.getString(context, SharedConstants.USER_TOKEN);
        JoinCircleServer joinCircleServer = ApiWrapper.getInstance().create(JoinCircleServer.class);
        Call<JoinCircleBean> joinBean = joinCircleServer.getJoinBean(token, Integer.parseInt(object_id), 1, 1);
        joinBean.enqueue(new Callback<JoinCircleBean>() {
            @Override
            public void onResponse(Call<JoinCircleBean> call, Response<JoinCircleBean> response) {
                JoinCircleBean body = response.body();
                if (body != null) {
                    int code = body.getCode();
                    if (code == 1) {
                        adJoin.dismiss();
                        MyToast.showToast(context, "加入圈子成功", Toast.LENGTH_SHORT);
                    } else if (code == 0) {
                        MyToast.showToast(context, "请登陆", Toast.LENGTH_SHORT);
                    } else if (code == 2500) {
                        MyToast.showToast(context, "需要登陆后才可以操作", Toast.LENGTH_SHORT);
                    } else if (code == 2501) {
                        MyToast.showToast(context, "不存在该书圈", Toast.LENGTH_SHORT);
                    } else if (code == 2502) {
                        MyToast.showToast(context, "您已经收藏过了！", Toast.LENGTH_SHORT);
                    } else if (code == 2506) {
                        MyToast.showToast(context, "抱歉您的账户被暂时限制了，无法进行此操作", Toast.LENGTH_SHORT);
                    } else if (code == 2507) {
                        MyToast.showToast(context, "系统繁忙，请您稍后再试！", Toast.LENGTH_SHORT);
                    }
                }
            }

            @Override
            public void onFailure(Call<JoinCircleBean> call, Throwable t) {
                MyToast.showToast(context, "系统繁忙，请您稍后再试！", Toast.LENGTH_SHORT);
            }
        });
    }
    /*点发消息---或者默认的时候 -- 显示编辑输入框的diaolog*/
    private Dialog myEditTextDialog;
    private EditText etInvitation;
    private TextView tvInvitation;
    private InputMethodManager imm;

    private void showEditTextDialog() {
        View view = context.getLayoutInflater().inflate(R.layout.my_edittext_dialog,
                null);
        etInvitation = (EditText) view.findViewById(R.id.et_invitation);
        tvInvitation = (TextView) view.findViewById(R.id.tv_invitation);
        myEditTextDialog = new Dialog(context, R.style.transparentFrameWindowStyle);
        myEditTextDialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
          /*监听edittext内容发生变化是的操作*/
        etInvitation.addTextChangedListener(new MyEditTextChangeListener());
        /*监听edittext获取失去焦点时的操作*/
        etInvitation.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean b) {
                /*此处为得到焦点时的操作*/
                if (b) {
                    // JudeWheTherMessage();
                } else {
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                    //此处为失去焦点时的区别
                    etInvitation.setHint("");
                }
            }
        });
        tvInvitation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                publicData();
            }
        });
        Window window = myEditTextDialog.getWindow();
        /*设置去掉dialog四周的边距*/
        window.getDecorView().setPadding(0, 0, 0, 0);
        // 设置显示动画
        //   window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = context.getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        /*解决软键盘把dialog盖住的问题*/
        myEditTextDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        myEditTextDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        // 设置显示位置
        myEditTextDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        myEditTextDialog.setCanceledOnTouchOutside(true);
        myEditTextDialog.show();
    }

    /*发表的接口*/
    private void publicData() {
        String trim = etInvitation.getText().toString().trim();
        String pinglunContent = DeleteHtml.HtmlText.Html2Text(trim);
        if (TextUtils.isEmpty(pinglunContent)) {
            MyToast.showToast(context, "请输入内容", Toast.LENGTH_SHORT);
        } else {
            PostCommentServer postCommentServer = ApiWrapper.getInstance().create(PostCommentServer.class);
            Call<PostCommentBean> postComment = postCommentServer.getPostComment(token, uid, secondToUid, id, secondObjectId, pinglunContent, pid);
            postComment.enqueue(new Callback<PostCommentBean>() {
                @Override
                public void onResponse(Call<PostCommentBean> call, Response<PostCommentBean> response) {
                    PostCommentBean body = response.body();
                    int code = body.getCode();
                    if (code == 1) {
                        // forumLzlReply.notify();
                        commentAdapter.notifyDataSetChanged();
                        MyToast.showToast(AttenttionDetailAdapter.this.context, "评论成功", Toast.LENGTH_SHORT);
                        myEditTextDialog.cancel();
                        context.requesData();
                    } else if (code == 2700) {
                        MyToast.showToast(context, "需要登陆后才可以操作", Toast.LENGTH_SHORT);
                    } else if (code == 2701) {
                        MyToast.showToast(context, "抱歉您的账户被暂时限制了，无法进行此操作", Toast.LENGTH_SHORT);
                    } else if (code == 2702) {
                        MyToast.showToast(context, "该帖子不存在或者被冻结！", Toast.LENGTH_SHORT);
                    } else if (code == 2703) {
                        MyToast.showToast(context, "该帖子存在不正当的异常，麻烦建议给我们", Toast.LENGTH_SHORT);
                    }

                }

                @Override
                public void onFailure(Call<PostCommentBean> call, Throwable t) {
                    MyToast.showToast(context, "网络异常，请稍后重试", Toast.LENGTH_SHORT);
                }
            });
        }
    }

    /*评论回复*/
    private void pingLunHuifu(int parentPosition, int position) {
        //  InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        //imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
        imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(etInvitation, InputMethodManager.SHOW_FORCED);
        /*在这里获取一级评论下的二级评论*/
        List<NewAllAttentionBean.InfoBean.AllCommentBean.SonCommentBean> son_comment = forumLzlReply.get(parentPosition).getSon_comment();
        int size = son_comment.size();
        String comment_name = son_comment.get(position).getComment_name();
        String to_comment_name = son_comment.get(position).getTo_comment_name();
        etInvitation.setHint(Html.fromHtml("回复@" + "<font color= '#576b95'>" + comment_name + "</font>" + ":"));
        /*帖子的id*/
        secondId = son_comment.get(position).getId();
        /*被回复人的id*/
        secondToUid = son_comment.get(position).getUid();
       /*贴子的id---这里指一级评论的pid*/
        secondPid = son_comment.get(position).getTo_uid();
        /*圈子的id*/
        secondObjectId = this.object_id;
        /*pid--如果是二级评论那么对应的就是一级评论的id，如果是一级评论那么这个参数的值就是0*/
        pid = son_comment.get(position).getPid();
    }

    private class MyEditTextChangeListener implements TextWatcher {
        /*内容发生变化时*/
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            tvInvitation.setText("发表");
            tvInvitation.setTextSize(18);
            // tvInvitation.setPadding(20, 4, 20, 4);
            // tvInvitation.setBackgroundResource(R.drawable.invitation_publishs_shape);
        }

        /*
        *编辑框的内容正在发生改变时的回调方法 >>用户正在输入
        * 我们可以在这里实时地 通过搜索匹配用户的输入
        * */
        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            CharSequence text = etInvitation.getText();
            if (text instanceof Spannable) {
                Spannable spanText = (Spannable) text;
                Selection.setSelection(spanText, text.length());
                if (charSequence.length() == 0) {
                    tvInvitation.setText("发表");
                    // tvInvitation.setBackgroundResource(R.drawable.invitation_publish_shape);
                    tvInvitation.setTextColor(context.getResources().getColor(R.color.create_circle_type));
                } else {
                    tvInvitation.setText("发表");
                    tvInvitation.setTextColor(context.getResources().getColor(R.color.red));
                }
            }

        }

        /*
        * 编辑框的内容改变以后,用户没有继续输入时 的回调方法
        * */
        @Override
        public void afterTextChanged(Editable editable) {
        }
    }

    public List<NewAllAttentionBean.InfoBean.AllCommentBean> getList() {
        return forumLzlReply;
    }
}
